package temp;

import org.apache.logging.log4j.Logger;

import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;
import javax.persistence.EntityManager;
import java.util.List;

/**
 * 09.11.14
 *
 * @author horec
 */
@Named
@RequestScoped
public class BookController {
    @Inject
    private Logger log;
    @Inject
    @WidgetRepository
    private EntityManager widgetRepository;

    private List<Book> books;

    public List<Book> getBooks() {
        return books;
    }

    @PostConstruct
    public void loadBooks(){
        log.debug("BookController.loadBooks");
        //noinspection unchecked
        books = widgetRepository.createQuery("select b from Book b").getResultList();
    }
}
